<?php

class PatientController extends \BaseController {

	public $restful = true;

	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */
	public function index()
	{
		return Response::json(Patient::orderBy('pat_id', 'desc')->get());
	}


	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function create()
	{
		return Response::json(Patient::get());
	}


	/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
	public function store(){
		$patient = new Patient;

		$patient->name = Input::json('name');
		$patient->lastname = Input::json('lastname');
		//$patient->idty_id = Input::json('idty_id');
		$patient->identification_number = Input::json('identification_number');
		$patient->cou_id = Input::json('cou_id');
		$patient->city = Input::json('city');
		$patient->birthday = Input::json('year') . '-' . Input::json('month') . '-' . Input::json('day');
		$patient->gender = Input::json('gender');
		//$patient->mast_id = Input::json('mast_id');
		//$patient->occ_id = Input::json('occ_id');
		//$patient->main_address = Input::json('main_address');
		
		$patient->save();

		return Response::json($patient);
	}


	/**
	 * Display the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		$patient = DB::table('patient')->where('pat_id', $id)->first();
		
		$birthday = explode('-', $patient->birthday);
		$patient->day = (int) $birthday[2];
		$patient->month = (int) $birthday[1];
		$patient->year = (int) $birthday[0];

		return Response::json($patient);
	}


	/**
	 * Show the form for editing the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		//
	}


	/**
	 * Update the specified resource in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{

	}


	/**
	 * Remove the specified resource from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		//
	}


}
